package com.dragon.logical.service.auth.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.common.model.ResultCode;
import com.dragon.common.model.exception.CustomException;
import com.dragon.repository.entity.Team;
import com.dragon.repository.mapper.TeamMapper;
import com.dragon.logical.service.auth.TeamService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sy
 * @since 2023-06-28
 */
@Service
public class TeamServiceImpl extends ServiceImpl<TeamMapper, Team> implements TeamService {

    @Autowired
    TeamMapper mapper;

    @Override
    public Page<Team> teamList(Integer id) {
        Page<Team> teamPage = new Page<>();
        return mapper.selectTeam(teamPage,id);
    }

    @Override
    public void add(Team team) {
        Team one = mapper.selectOne(new QueryWrapper<Team>().lambda().eq(Team::getAdminId, team.getAdminId()));
        if (one != null){
            throw new CustomException(ResultCode.DATA_ALREADY_EXISTS);
        }
        mapper.insert(team);
    }
    
    @Override
    public void delete(Integer id){
        mapper.deleteById(id);
    }
}
